package com.hzz.dao.dsync;

import com.hzz.framework.dao.IBaseDao;
import com.hzz.framework.entity.IEntity;
import org.apache.ibatis.annotations.*;

/**
 * <p>系统_云端同步 数据库处理接口类。
 */
@Mapper
public interface IDSyncExistDao extends IBaseDao {
    /**
     * 判断是否存在
     */
    @Select("select IFNULL(count(0),0) as count from dsync_exist where  id = #{id}")
    int isDataExistById(@Param("id") String id) throws Exception;
    /**
     * 判断是否完成
     */
    @Select("select IFNULL(count(0),0) as count from dsync_exist where  id = #{id} and state = 1")
    int isDataFinishById(@Param("id") String id) throws Exception;

    int dataStatistics(IEntity entity) throws Exception;

    @Update("update dsync_exist set date_updated=now() ,version=version+1  ,state = #{state} ,djson = #{djson} , result = #{result} where id = #{id} ")
    int updateById(IEntity entity) throws Exception;

    /**
     * 根据主键 物理删除
     */
    @Override
    @Delete("delete from dsync_exist where id = #{id} ")
    int deleteByPrimaryKey(IEntity entity) throws Exception;

    /**
     * 根据过期天数 物理删除
     */
    @Delete("delete from dsync_exist where IFNULL(datediff(DATE_FORMAT(now(),'%Y%m%d'),DATE_FORMAT(date_created,'%Y%m%d')),999)>#{expireDay} ")
    int deleteByExpireDay(@Param("expireDay") Integer expireDay) throws Exception;

    /**
     * 删除已同步日志
     */
    @Delete("delete from dsync_exist where state = 1 ")
    int deleteByState() throws Exception;
}
